//
//  TJHomeDetaiCell.m
//  Teleport
//
//  Created by hc-101 on 2020/6/16.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJTopUpRecordCell.h"


@interface TJTopUpRecordCell()


@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *numberValueLabel;
@property (strong, nonatomic) UILabel *stateValueLabel;
@property (strong, nonatomic) UILabel *timeValueLabel;


@end


@implementation TJTopUpRecordCell

- (void)settingSubView {
    
    
    _titleLabel = [UILabel lableWithSuperView:self.contentView font:MediumFont(15) color:UIColor_Hex(0x262626) title:@"" textAlignment:NSTextAlignmentLeft];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.top.offset(16);
    }];
    
    UILabel *numberLabel = [UILabel lableWithSuperView:self.contentView font:UIFont_Px(14) color:UIColor_Hex(0x656565) title:@"数量".localizedString textAlignment:NSTextAlignmentLeft];
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_titleLabel);
        make.top.equalTo(_titleLabel.mas_bottom).offset(6);
    }];
    
    
    _numberValueLabel = [UILabel lableWithSuperView:self.contentView font:UIFont_Px(14) color:UIColor_Hex(0x656565) title:@"" textAlignment:NSTextAlignmentLeft];
    [_numberValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_titleLabel);
        make.top.equalTo(numberLabel.mas_bottom).offset(6);
    }];
    
    
    UILabel *stateLabel = [UILabel lableWithSuperView:self.contentView font:UIFont_Px(14) color:UIColor_Hex(0x656565) title:@"状态".localizedString textAlignment:NSTextAlignmentLeft];
    [stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.centerY.equalTo(numberLabel);
    }];
    
    
    _stateValueLabel = [UILabel lableWithSuperView:self.contentView font:UIFont_Px(14) color:UIColor_Hex(0x656565) title:@"" textAlignment:NSTextAlignmentLeft];
    [_stateValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.centerY.equalTo(_numberValueLabel);
    }];
    
    
    UILabel *timeLabel = [UILabel lableWithSuperView:self.contentView font:UIFont_Px(14) color:UIColor_Hex(0x656565) title:@"时间".localizedString textAlignment:NSTextAlignmentRight];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-16);
        make.centerY.equalTo(stateLabel);
    }];
    
    
    _timeValueLabel = [UILabel lableWithSuperView:self.contentView font:UIFont_Px(14) color:UIColor_Hex(0x656565) title:@"" textAlignment:NSTextAlignmentRight];
    [_timeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-16);
        make.centerY.equalTo(_stateValueLabel);
    }];
    
    
}

- (void)setModel:(TJTopUpRecord *)model {
    _model = model;
    
    _titleLabel.text = model.type.replacingEmptyString.length != 0 ? model.type : model.currency;
    _numberValueLabel.text = model.balance ?: model.amount;
    _stateValueLabel.text = [self stateValue:model.state ?: @"PASS"];
    _timeValueLabel.text = model.extractTime ?:[self convertStrToTime:model.createTime];
}

 //CREATE 等待审核  PASS 审核通过  REJECT 拒绝
- (NSString *)stateValue:(NSString *)state {
    if ([state isEqualToString:@"PASS"]) return @"已成功".localizedString;
     if ([state isEqualToString:@"CREATE"]) return @"审核中".localizedString;
    if ([state isEqualToString:@"REJECT"]) return @"审核失败".localizedString;
    return @"已成功";
}

- (NSString *)convertStrToTime:(NSString *)timeStr {
    long long time=[timeStr longLongValue]/1000;
    NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:time];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString*timeString=[formatter stringFromDate:date];
    return timeString;
}

@end
